import java.awt.Graphics;
import java.awt.Image;
// import java.awt.Point;
import java.awt.Toolkit;

public class FontHandler
{

	private Image img;
	// private Point tileSize;
	private static FontHandler si = null;

	// float x_scale, y_scale;

	private String[] line;
	private String palette = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890. ,;(:*!?')\"/\\<>";

	private int maxLines = 12;

	private FontHandler()
	{
		img = Toolkit.getDefaultToolkit().createImage("5by5font.PNG");

		// x_scale = (max_x / map_w) / tileSize.x;
		// y_scale = (max_y / map_h) / tileSize.y;
		// tileSize.x = 6;
		// tileSize.y = 6;

		line = new String[maxLines];
		for (int t = 0; t < maxLines; t++)
		{
			line[t] = " ";
		}

	}

	public static FontHandler getInstance()
	{
		if (si == null)
		{
			si = new FontHandler();
		}
		return si;
	}

	public void draw(Graphics g)
	{

		for (int w = 0; w < maxLines; ++w)
		{
			int x, y, l, charToUse;

			for (l = 0; l < line[w].length(); ++l)
			{
				charToUse = palette.lastIndexOf(line[w].substring(l, l + 1));

				y = w + 37; // These are the screen offsets for where the text
				// should appear.
				x = l + 1;

				g.drawImage(img, (x * 6), (y * 6), (x * 6) + 6, (y * 6) + 6,
						(charToUse * 6), 0, (charToUse * 6) + 6, 0 + 6, null);

				// TODO: Find out why this shit doesn't work. NuPuRo
				/*
				 * g.drawImage(img, (x * tileSize.x), (y * tileSize.y), (x *
				 * tileSize.x) + tileSize.x, (y * tileSize.y) + tileSize.y,
				 * (charToUse * tileSize.x), 0, (charToUse * tileSize.x) +
				 * tileSize.x, 0 + tileSize.y, null);
				 */
			}
		}

	}

	public void addLine(String text)
	{
		if (!text.matches(""))
		{
			for (int w = 0; w < (maxLines - 1); w++)
			{
				line[w] = line[w + 1];
			}
			line[(maxLines - 1)] = text;
		}
	}

	public void overWrite(String text)
	{
		line[(maxLines - 1)] = text;
	}

}
